

export const COLS = [
    1, 2, 3, 4, 5, 6,
]

export function cargo_position_with_col(col: number) {
    return (col - 1) * 483;
}

export const ROWS = [
    1, 2, 3, 4, 5,
    6, 7, 8, 9, 10,
    11, 12, 13, 14, 15,
    16, 17, 18, 19, 20,
    21, 22, 23, 24, 25,
];

export interface RowInfo {
    row: number,
    position: number,
}
// 链条长度: 2870.2mm
// 同步轮 40, 26
// 减速器 10
// 大齿轮周长 762mm
// 行间距 114.3,  第二行: 114.3 + 12.7
function cargo_position_with_mm(mm: number) {
    const val = 40 / 26 * 10 * 400 / 762 * mm;
    return Math.round(val);
}

function cargo_position_with_row(row: number, other: number = 0) {
    // let mm = 6.35;
    // if (row == 1) {
    //     row = 0
    // } else if (row == 2) {
    //     mm = 114.3 + 6.35;
    // } else if (row <= 25) {
    //     mm = 114.3 * (row - 1) + 6.35;
    // } else {
    //     throw 'invalid row';
    // }
    return cargo_position_with_mm(114.3 * (row - 1) + other)
}

// 400 4
export function cargo_scan_position_with_row(row: number) {
    // 3 25
    // 2 24
    // 1 23
    let n = row - 3;
    let other = 0;
    if (row <= 3) {
        other = 12.7;
        n = row + 22;
    }
    return cargo_position_with_row(n, other) + 450;
}

export function cargo_pick_position_with_row(row: number) {
    let n = row - 4;
    let other = 0;
    if (row <= 4) {
        n = row + 21;
        other = 12.7;
    }
    return cargo_position_with_row(n, other) + 380;
}

/**
 * 1   102
 * 2   204
 * 3   306
 * 4   411
 * 5 ..
 * 6 ..
 * 25 .. 
 */